function [KNNList, SortedDistTable] = Ddavid_find_knn_from_training_data(K, AllDataTesting, AllDataTraining)

disp(['Ddavid_find_knn_from_training_data K = ' num2str(K)]);

TestingN = size(AllDataTesting, 1);
KNNList = zeros(TestingN, K);
SortedDistTable = zeros(TestingN, K);

for i = 1:TestingN
    AllDist = dist2(AllDataTesting(i, :), AllDataTraining);
    [DistTable, Index] = sort(AllDist);
    KNNList(i, :) = Index(1, 1:K);
    SortedDistTable(i, :) = DistTable(1, 1:K);
end
